package hczc.longcai.com.hccrowdfunding.search;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import hczc.longcai.com.hccrowdfunding.R;
import hczc.longcai.com.hccrowdfunding.application.BaseApplication;

/**
 * Created by Administrator on 2016/1/19.
 */
public class HotSearchAdapter extends BaseAdapter {

    private static final String TAG = "HotSearchAdapter";
    private Context context;
    private String[] strings;
    private int[] background = {R.drawable.search_black, R.drawable.search_blue, R.drawable.search_gold, R.drawable.search_gray, R.drawable.search_red};

    public HotSearchAdapter(Context context, String[] strings) {
        this.context = context;
        this.strings = strings;
    }



    @Override
    public int getCount() {
        return strings.length;
    }

    @Override
    public Object getItem(int i) {
        return strings[i];
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        int drawable = getDrawable();
        if(view == null){
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.item_hot_search,null);
            BaseApplication.scaleScreenHelper.loadView(((ViewGroup) view));
            holder.textView = ((TextView) view.findViewById(R.id.item_hot_search_gridview));
            holder.textView.setBackgroundResource(drawable);
            view.setTag(holder);

        }
        holder = ((ViewHolder) view.getTag());
        holder.textView.setText(strings[i]);

        return view;
    }

    private int getDrawable(){
        int i = 0;
        int random = (int) (Math.random() * 10 % 5);
        i = background[random];
//        Log.d(TAG,"生成的随机数是："+random);
        return i;
    }

    class ViewHolder{
        TextView textView;
    }
}
